 package view.diaLogView;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.text.R;

import java.util.HashMap;
import java.util.Map;

import util.BReceiverUtil.SMSBroadcastReceiver;
import util.HomeUtil;
import util.StringUtil;
import util.Url;

 /**
  * Created by Administrator on 2016/6/21.
  *提示选短信接收还是电话给验证码
  */
 public class PhoneMessageDialog extends Dialog {
     private Context mContext;
     private String mStringPhone,mFWQString;
     private EditText mEditText;
     private TextView mTextView;
     private  HashMap<String,Object> mMap;
     private PhoneMessageDialog mPhoneMessageDialog;
     public PhoneMessageDialog(Context context,String phone,String fwq,EditText editText,TextView textView) {
         super(context, R.style.lable_del_dialog);
         this.mContext = context;
         this.mFWQString = fwq;
         this.mStringPhone = phone;
         this.mEditText = editText;
         this.mTextView = textView;
         mPhoneMessageDialog = this;
     }

     @Override public void show() {
         Window window = getWindow();
         window.setGravity(Gravity.BOTTOM);
         window.setWindowAnimations(R.style.upoad_dialog);
         super.show();
     }

     @Override protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         init();
     }

     private void init() {
         ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
         params.width = mContext.getResources().getDisplayMetrics().widthPixels;
         LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         View mView = inflater.inflate(R.layout.phone_message_dialog,null);
         TextView TVMessage= (TextView)mView.findViewById(R.id.tv_dialog_message); //短信提示
         TextView TVPhone = (TextView)mView.findViewById(R.id.tv_dialog_phone); //电话提示
         final LinearLayout linearLayout1 = (LinearLayout)mView.findViewById(R.id.linear_retu1);
         LinearLayout linearLayout2 = (LinearLayout)mView.findViewById(R.id.linear_retu2);

         linearLayout1.setOnClickListener(new View.OnClickListener() {
             @Override public void onClick(View v) {
                 mPhoneMessageDialog.dismiss();
             }
         });

         linearLayout2.setOnClickListener(new View.OnClickListener() {
             @Override public void onClick(View v) {
                 mPhoneMessageDialog.dismiss();
             }
         });

         TVMessage.setOnClickListener(new View.OnClickListener() {
             @Override public void onClick(View v) {
                 HomeUtil.getHemeUtilNew().getMessage(mContext,mEditText,new SMSBroadcastReceiver());
                 mMap = new HashMap<>();
                 mMap.put("phone",mStringPhone);
                 mMap.put("authCodeType",0);
                 String stringJson = StringUtil.getStringUtilNew().hashMapToJson(mMap); //参数包
                 long time = StringUtil.getStringUtilNew().getTimeCurrent();
                 String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngPhoneVerification,stringJson,"null","0",time);
                 Map map1 = StringUtil.getStringUtilNew().getMapNew(mContext,stringJson,"null","0",Url.mStirngPhoneVerification,stirngSign,time);
                 HomeUtil.getHemeUtilNew().obtainVerification(mContext,map1,mFWQString,mTextView,0,2);
                 mPhoneMessageDialog.dismiss();
             }
         });

         TVPhone.setOnClickListener(new View.OnClickListener() {
             @Override public void onClick(View v) {
                 HomeUtil.getHemeUtilNew().getMessage(mContext,mEditText,new SMSBroadcastReceiver());
                 mMap = new HashMap<>();
                 mMap.put("phone",mStringPhone);
                 mMap.put("authCodeType",1);
                 String stringJson = StringUtil.getStringUtilNew().hashMapToJson(mMap); //参数包
                 long time = StringUtil.getStringUtilNew().getTimeCurrent();
                 String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngPhoneVerification,stringJson,"null","0",time);
                 Map map1 = StringUtil.getStringUtilNew().getMapNew(mContext,stringJson,"null","0",Url.mStirngPhoneVerification,stirngSign,time);
                 HomeUtil.getHemeUtilNew().obtainVerification(mContext,map1,mFWQString,mTextView,1,2);
                 mPhoneMessageDialog.dismiss();
             }
         });

         setContentView(mView, params);
     }



 }
